<div class="box white_bg">
<?if (isset($this->viewParams['mails'])) :?>

<table width = "100%">
<tr height = "20">
		<a href= "#" class = "mail-action" value = "2" name = "status" ><?=t(31)?></a>&nbsp;&nbsp;&nbsp;&nbsp; 
		<a href= "#" class = "mail-action" value = "1" name = "status" ><?=t(1022)?></a>&nbsp;&nbsp;&nbsp;&nbsp;
		<a href= "#" class = "mail-action" value = "0" name = "status" ><?=t(1023)?></a>&nbsp;&nbsp;&nbsp;&nbsp;
		<a href= "#" class = "mail-action" value = "2" name = "flag" ><?=t(116)?></a>&nbsp;&nbsp;&nbsp;&nbsp;
		<a href= "#" class = "mail-action" value = "1" name = "flag" ><?=t(1024)?></a>&nbsp;&nbsp;&nbsp;&nbsp; 
		<a href= "#" class = "mail-action" value = "0" name = "flag" ><?=t(1025)?></a>&nbsp;&nbsp;&nbsp;&nbsp; 
</tr>

<tr style="font-weight:bold">
<td width="5%">
 <input type="checkbox" name = "check_status"/> 
</td>
<td width="12%">
<?=t(1024)?>
</td>
<td  width="20%">
<?=t(1026)?>
</td>
<td  width="50%">
<?=t(13)?>
</td>
<td width="15%">
<?=t(20)?>
</td>
</tr>
<?foreach ($this->viewParams['mails'] as $node) :?>
	<? $node['metadata'] = unserialize($node['metadata']) ?>
<? if ($node['status'] == 0) :?>
<!-- bold -->
<tr id="row-<?=$node['id']?>" style="font-weight:bold">
<?else :?>
<tr id="row-<?=$node['id']?>">
<?endif ?>
<td>
<!--<input type="checkbox" /><?=$node['id']?>-->
<input type="checkbox" class = "node_tick" value="<?=$node['id'] ?>" id="edit-nodes-<?=$node['id'] ?>" name="nodes[<?=$node['id'] ?>]" />
</td>

<td>

</td>

<td>
	<?if (file_exists(APP_PATH."/public/ufiles/".$node['poster_id']."/images/original/avatar/avatar.jpg"))
		{
			$avatar_image = "/public/ufiles/".$node['poster_id']."/images/%s/avatar/avatar.jpg";
		}
	?>
	<img src="<?=sprintf($avatar_image, "xxsmall");?>" alt="avatar xxsmall"/> <br/>
	<?=$node['metadata']['poster_name'] ?>
</td>

<td>
 <a href="<?=$this->hvnUrl(array("module" => "user",
						"controller" => "account",
						"action" => "read-mail"),
 						"generic")?>?id=<?=$node['id']?>" >
<? if ($node['title_is_reply'] == 0) :?>
	<?=$node['title'] ?>
<?else :?>
	Re: <?=$node['title'] ?>
<?endif ?>
 </a>
</td>
<td>
	<?=date("j/n/Y", $node['created'])?>
</td>
</tr>
<?endforeach?>
</table>
<?endif ?>
</div>

<script>
$(function() {

	$(".ajax-delete").click(function(){
    	url = $(this).attr('name');
    	id = $(this).attr('title');
    	$.getJSON(url, {}, 
	    	function(data){
				if (data.success == false)
				{
					alert(data.errorMessage);
				}
				else
				{
					alert("Success" + "#row-" + id);
					$("#row-" + id).css("background-color","red").fadeOut(1000);
				}
    		});
    	});

	$("input[name=check_status]").toggle(function(){
		$(".node_tick").attr('checked', 'checked');
		
	},
	function(){
		$(".node_tick").removeAttr('checked'); 
	});

	$("a.mail-action").click(function(){
	    value = $(this).attr('value');
     	name = $(this).attr('name');
	     //lay ids
	    ids = '';
	    $.each($("[id^=edit-nodes]"),function(){
     		if($(this).attr('checked') == true)
         		if(ids == '')
            		ids = ids + $(this).val();
         		else
         			ids = ids  + ',' + $(this).val();
		});
	    //generate url
	    url = 'node/ajax/set-status';
	    $.getJSON(url, {'ids': ids , 'name' : name, 'value' : value}, function(json)
	    {
	    	if(json.success){	
		    		$.each(json.ids,function(i,id){
			    		$("#edit-nodes-" + id).removeAttr('checked');
			    		if((json.name == 'status' || json.name == 'flag' ) &&  json.value == 2)	 
			    			$("#row-" + id).hide();
			    	});
			    }                  
            return false;
	    });
	 });
});
</script>
